package com.qiaofang.controller;

import com.qiaofang.common.response.CommonResponse;
import com.qiaofang.dto.PremisesDynamicDTO;
import com.qiaofang.request.*;
import com.qiaofang.response.*;
import com.qiaofang.service.PremisesDynamicService;
import com.qiaofang.service.V10ApiService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.MimeTypeUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.text.ParseException;

@RestController
@Api(tags = {"楼盘动态"})
@RequestMapping(value = "/dynamic", produces = MimeTypeUtils.APPLICATION_JSON_VALUE)
public class DynamicController {

    @Autowired
    private PremisesDynamicService premisesDynamicService;

    @Autowired
    private V10ApiService v10ApiService;

    @PostMapping(value = "/listPremisesDynamic")
    @ApiOperation(value = "楼盘动态列表")
    public ListPremisesDynamicResponse listPremisesDynamic(@RequestBody ListPremisesDynamicRequest request) throws ParseException {
        ListPremisesDynamicResponse response=new ListPremisesDynamicResponse();
        PremisesDynamicDTO dto = new PremisesDynamicDTO();
        /** 将请求值传入 dto */
        BeanUtils.copyProperties(request, dto);
        response.setData(premisesDynamicService.listPremisesDynamic(dto,request.getPage()));
        return response;
    }

    @PostMapping(value = "/getDynamicDetail")
    @ApiOperation(value = "查看楼盘动态详情")
    public GetDynamicDetailResponse getDynamicDetail(@RequestBody @Valid GetDynamicDetailRequest request) {
        GetDynamicDetailResponse response = new GetDynamicDetailResponse();
        response.setData(premisesDynamicService.getDynamicDetail(request.getId()));
        return response;
    }

    @PostMapping(value = "/findBindPremisesDynamic")
    @ApiOperation(value = "查询绑定V10动态")
    public BindDynamicResponse findBindPremisesDynamic(@RequestBody @Valid GetDynamicDetailRequest request){
        BindDynamicResponse response = new BindDynamicResponse();
        response.setData(premisesDynamicService.findBindPremisesDynamic(request.getId()));
        return response;
    }

    @PostMapping(value = "/pushDynamicToV10")
    @ApiOperation(value = "推送V10动态")
    public CommonResponse listApiLog(@RequestBody @Valid GetDynamicDetailRequest request) {
        return v10ApiService.pushDynamicToV10(request.getId());
    }
}
